-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Bson specification testing #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR reorganizes specification testing by moving the MongoDB specifications submodule from driver-core to a shared testing directory, updates JSON output for positive exponents to match the extended JSON specification, and adds comprehensive testing for BsonBinaryVector functionality.
- Moved specifications submodule from driver-core to shared testing directory for better organization
- Fixed JSON output to include explicit "+" signs for positive exponents in extended JSON
- Added comprehensive testing for BsonBinaryVector including prose tests and enhanced validation
Reviewed Changes
Copilot reviewed 47 out of 49 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| .gitmodules | Updated submodule path from driver-core to testing directory |
| bson/build.gradle.kts | Added test resource processing to include shared testing resources |
| driver-core/build.gradle.kts | Added test resource processing to include shared testing resources |
| bson/src/main/org/bson/json/*.java | Modified double converters to use consistent JSON formatting with explicit positive exponents |
| bson/src/main/org/bson/BinaryVector.java | Added validation logging for non-zero padding bits |
| bson/src/test/unit/org/bson/vector/BinaryVectorGenericBsonTest.java | Enhanced test coverage and updated to use new spec test location |
| bson/src/test/unit/org/bson/*.java | Updated test references to use new specification test helper method |
| bson/src/test/resources/bson*/ | Removed old BSON specification test files (now using submodule) |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Moved specifications submodule out of driver-core into a testing directory. Deleted old copy of bson specification tests and updated to use the submodule Fixed Json output for positive exponents to match the the extended json specification Added test exceptions to BinaryVectorGenericBsonTest Added BsonBinaryVector prose tests Added extra regression tests to ensure both explicit and implicit doubles with positive exponets parse as expected. JAVA-5877 JAVA-5779 JAVA-5782 JAVA-5652
Co-authored-by: Copilot <[email protected]>
|
|
||
| @DisplayName("Treatment of non-zero ignored bits: 2. Decoding") | ||
| @Test | ||
| void decodingWithNonZeroIgnoredBits() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BinaryVectorTest only covers use-cases for creating BinaryVectors from constructor methods of BinaryVector API.
We have a separate class BsonBinaryTest for decoding tests with methods:
shouldDecodeInt8Vector, shouldEncodePackedBitVector. I suggest we move decoding test method there to keep them coherent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this file to BinaryVectorProseTest as these include the new tests in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note there are corpus tests also that cover the BsonBinary api, these prose and extra tests allow for extra testing of the API.
| } | ||
|
|
||
| // TODO JAVA-5848 in 6.0.0 "Padding specified with no vector data PACKED_BIT" will throw an error (currently logs a warning). | ||
| if (testCase.containsKey("canonical_bson") && !testDescription.equals("Padding specified with no vector data PACKED_BIT")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already maintain a list of ignored tests in TEST_NAMES_TO_IGNORE. Should we move this check to TEST_NAMES_TO_IGNORE to keep it consistent and easier to track?
This would also simplify the method signature by removing the testDescription parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| BsonArray arrayVector = testCase.getArray("vector"); | ||
| byte expectedPadding = (byte) testCase.getInt32("padding").getValue(); | ||
| byte dtypeByte = Byte.decode(testCase.getString("dtype_hex").getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an error occurs in the test setup (for example, Byte.decode("") throwing an IllegalArgumentException, an intentional mistake in this case), all tests currently pass.
This happens because IllegalArgumentException and IllegalStateException are caught broadly in assertValidationException covering both the setup logic and the SUT, and treated as expected results.
While I see the benefit of a more generalized approach, I think we should assert exceptions only where they’re explicitly expected, as we did previously and still do in runValidTestCase.
That would separate test setup of code under test and reduce the risk of unintentionally masking setup errors as successful test results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| BinaryVector.packedBitVector(bytes, expectedPadding); | ||
| break; | ||
| case FLOAT32: | ||
| throw new IllegalArgumentException("Float32 is not supported"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, when a JSON test that we don’t support runs through the runner, it throws IllegalArgumentException, which propagates to assertValidationException and is treated as a successful execution.
Since we have a few such unsupported cases (9 in total, with only 4 currently reported as skipped via TEST_NAMES_TO_IGNORE), it could be clearer to surface them as skipped instead.
We could do that by throwing a TestAbortedException, for example: Assumptions.abort(dataType + " is not supported with padding");, so these cases are reported as skipped without implying they passed successfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| } | ||
|
|
||
| tasks.processTestResources { | ||
| from("${rootProject.projectDir}/testing/resources") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I think, In the future, we could also consider creating a separate module for testing utilities, so shared helpers can be reused across sync, reactive, core, and BSON modules.
Co-authored-by: Viacheslav Babanin <[email protected]>
Co-authored-by: Viacheslav Babanin <[email protected]>
Co-authored-by: Viacheslav Babanin <[email protected]>
|
@vbabanin I've updated the names of the tests to be more inline with the spec location and to identify the prose tests. I also moved the validation to the constructors as it seemed the best place to have it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code
| } | ||
|
|
||
| // TODO JAVA-5848 in 6.0.0 "Padding specified with no vector data PACKED_BIT" will throw an error (currently logs a warning). | ||
| if (testCase.containsKey("canonical_bson") && !testDescription.equals("Padding specified with no vector data PACKED_BIT")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| @DisplayName("Treatment of non-zero ignored bits: 2. Decoding") | ||
| @Test | ||
| void decodingWithNonZeroIgnoredBits() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this file to BinaryVectorProseTest as these include the new tests in the spec.
| BsonArray arrayVector = testCase.getArray("vector"); | ||
| byte expectedPadding = (byte) testCase.getInt32("padding").getValue(); | ||
| byte dtypeByte = Byte.decode(testCase.getString("dtype_hex").getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| BinaryVector.packedBitVector(bytes, expectedPadding); | ||
| break; | ||
| case FLOAT32: | ||
| throw new IllegalArgumentException("Float32 is not supported"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Moved specifications submodule out of driver-core into a testing directory.
Deleted old copy of bson specification tests and updated to use the submodule
Fixed Json output for positive exponents to match the the extended json specification
Added test exceptions to BinaryVectorGenericBsonTest
Added BsonBinaryVector prose tests
Added extra regression tests to ensure both explicit and implicit doubles with positive exponets parse as expected.
JAVA-5877
JAVA-5779
JAVA-5782
JAVA-5652